class Solution(object):
    def matrixReshape(self, nums, r, c):
        """
        :type nums: List[List[int]]
        :type r: int
        :type c: int
        :rtype: List[List[int]]
        """
        s = len(nums[0]) * len(nums)
        if r * c >s:
            return nums
        h = []
        for j in range(len(nums)):
            h.extend(nums[j])
        d = []
        for i in range(r):
            j = 0
            d.insert(i,[])
            while j<c:
                d[i].append(h[j])
                j+=1
            h = h[j:]

        return d
c = [[1,2],[3,4]]
s=Solution()
print(s.matrixReshape(c,4,1))